local mysql = require 'mysql'
local db, err = mysql:new()

if not db then
  ngx.say('fail to instantiate mysql: ', err)
  return
end

db:set_timeout(1000)


local ok,err,errno,sqlstate = db:connect({
  host='101.132.36.174',
  port=3306,
  database='game_dhg',
  user='zhy',
  password='zhy',
  max_packet_size=1024*1024
})

if not ok then
  ngx.say('failed to connect: ',err," : ",errno," ",sqlstate)
  return
end
  
ngx.say("connected!")

res,err,errno,sqlstate = db:query(string.format([[select * from dhg_user]]))

if not res then
  ngx.say("bad result: ",err," : ",errno," : ", sqlstate," .")
  return close_db(db)
end

for i, row in ipairs(res) do  
  for name, value in pairs(row) do  
    ngx.say("select row ", i, " : ", name, " = ", value, "<br/>")  
  end  
end  

-- close_db(db)
